package com.winning.bi.jdbc;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.rabbitmq.client.ConnectionFactory;
import com.winning.bi.amqp.ReceiveMessageUtils;
import com.winning.bi.processer.DbProcess;
import com.winning.bi.processer.EventProcesser;

/**
 * 
 * 
 * @author 张大川 消费者，消费数据。
 */
public class Consumer {
	public static void main(String[] args) throws Exception {
		Configuration config = new PropertiesConfiguration("config/amqp.properties");

		ConnectionFactory factory = new ConnectionFactory();

		factory.setHost(config.getString("hostname"));
		factory.setUsername(config.getString("username"));
		factory.setPassword(config.getString("password"));
		
		ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("file:config/consumer.xml");
		EventProcesser eventProcesser = new DbProcess();
		eventProcesser.setAc(ac);
		eventProcesser.setConfiguration(config);
		ReceiveMessageUtils messageUtils = new ReceiveMessageUtils(factory.newConnection());
		messageUtils.receiveMessage(config.getString("queue"), eventProcesser);

	}
}
